package jk.zmn.socket.udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

/**
 * @author 张梦楠
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2018/5/3010:47
 * @blog www.itzmn.com
 *
 *  UDP服务端
 *  1.创建服务端
 *  2.创建接收数据的容器
 *  3.接收数据
 *  4.解析
 *  5.关闭资源
 */
public class Server {


     public static void main(String[] args) throws Exception {

         //创建服务端
         DatagramSocket server = new DatagramSocket(8888);

         //准备存放数据的容器
         byte[] con = new byte[1024];
         //创建数据包
         DatagramPacket packet = new DatagramPacket(con,con.length);

         //解析数据
         server.receive(packet);
         //得到数据
         byte[] data = packet.getData();
         System.out.println(new String(data,0,packet.getLength()));

         server.close();



     }


}
